/*
url: http://www.ronipl.com
author: Roni Pinili
2013 copyright
*/



$(document).ready(function(){

			$('<div/>', {
   				 'id': 'preloader-wrapper'
  			}).insertBefore('#wrapper');

			var preloader = $('<div/>', {
   				 'id': 'preloader',
   				 'text': 'Loading contents...'
  			});

			var loader = $('<div/>', {
   				 'id': 'loader'
  			});


  			var status = $('<div/>', {
   				 'id': 'status'
  			});

  			$('#preloader-wrapper').append(preloader);
  			$(preloader).append(loader);
  			$(loader).append(status);
			
			var winHeight =  $(window).height();
			var preloaderHeight = $("#preloader").height();
			var preloaderHeightTotal =  winHeight/2 - preloaderHeight/2;

			var winWidth = $(window).width();
			var preloaderWidth = $("#preloader").width();
			var preloaderWidthTotal = winWidth/2 - preloaderWidth/2;	

		
		$("#preloader").css({top: preloaderHeightTotal, left: preloaderWidthTotal });

			function loop(){	
				$("#status").css({left:0});
				$("#status").animate({
					left: "+=170"
				}, 2000, "linear", function(){
					$(this).animate({
						left: "-=170"
					}, 2000, "linear", function(){
						loop();
					});
				});
			}loop();

		});
		$(window).load(function(){
			$("#preloader-wrapper").delay(350).fadeOut("slow");	
			$("body").delay(350).css({"overflow":"visible"});
		});